const path = require('path');
const tsconfigPlugins = require('tsconfig-paths-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const currentDir = path.resolve(__dirname);

const workDir = path.resolve(currentDir);
console.log("当前工作路径:" + workDir);

module.exports = {
    entry: path.resolve(workDir, './src/server/ServerStart.ts'),
    output: {
        filename: 'bundle.js',
        path: path.resolve(workDir, './bin/server'),
        libraryTarget: 'commonjs2'
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.(md|txt|glsl|vs|fs)$/,
                use: "raw-loader",
                exclude: /node_modules/
            },
        ],
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js', 'glsl', 'md', 'txt'],
        plugins: [
            new tsconfigPlugins({
                configFile: path.join(workDir, './tsconfig.json'),
            })
        ],
    },
    externalsPresets: { node: true }, // in order to ignore built-in modules like path, fs, etc.
    externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
    devtool: 'source-map',
    mode: 'development',
};